package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.druid.util.StringUtils;
import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;
import com.frogs.ucenter.entity.UserProtection;

public class UserProtectionSaveRequest extends Request {
	
	private UserProtection userProtection;


	public UserProtection getUserProtection() {
		return userProtection;
	}


	public void setUserProtection(UserProtection userProtection) {
		this.userProtection = userProtection;
	}


	/**
	 * 解析说明：用户账号保护信息与用户账号绑定，id应为用户id，此时，传进来如果缺少用户id，系统无法进行绑定，此记录没意义，所以保存此记录的前提是用户id是存在的
	 */
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		int id = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		String question = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.question.getParamName()));
		String answer = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.answer.getParamName()));
		
		if(id == 0 || StringUtils.isEmpty(question) || question.trim().length()==0
				|| StringUtils.isEmpty(answer) || answer.trim().length()==0) {
			throw new RequestIllegalException("传递错误的参数，请确认!用户是否存在!");
		}
		
		this.userProtection = new UserProtection(id,question,answer);
	}

}
